package com.situ.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/login")
public class LoginServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("LoginServlet.service()");
		req.setCharacterEncoding("utf-8");
		
		String name = req.getParameter("name");
		String password = req.getParameter("password");
		
		// 模拟如果名字是zhangsan，密码是123认为就是正确 的用户名密码
		if ("zhangsan".equals(name) && password.equals("123")) {
			User user = new User("zhangsan", "123");
			HttpSession session = req.getSession();
			session.setAttribute("user", user);
			resp.sendRedirect(req.getContextPath() + "/student");
		} else {
			resp.sendRedirect(req.getContextPath() + "/fail.jsp");
		}
		
		
	}
}
